import 'package:sow_app_core/sow_app_core.dart';
import 'package:sow_app_i18n/sow_app_i18n.dart';

import 'user_info_model.dart';

class BookShelfModel {
  final String novelId;
  final UserInfoModel? user;
  final String title;
  final String? wordCount;
  final String? visitCount;
  final String? isVip;
  final String? lastUpdateTime;
  final String cover;

  BookShelfModel.fromJson(Map<String, dynamic> json)
      : novelId = json['bookId'],
        title = json['bookName'],
        wordCount = json['wordCount'],
        visitCount = json['visitCount'],
        isVip = json['isVip'],
        lastUpdateTime = json['lastIndexUpdateTime'],
        user = json['user'],
        cover = json['cover'] ??
            'http://${I18n.backend_ip}:${I18n.backend_port}${I18n.base_cover_url}';

  toEntity() => Novel(
      novelId: novelId,
      title: title,
      author: user?.nickName ?? '',
      wordCount: wordCount,
      isVip: isVip,
      novelTypeList: [],
      visitCount: visitCount,
      lastUpdateTime: lastUpdateTime,
      cover: cover);

  toJson() => {
        'bookId': novelId,
        'bookName': title,
        'wordCount': wordCount,
        'visitCount': visitCount,
        'isVip': isVip,
        'lastIndexUpdateTime': lastUpdateTime,
        'user': user?.toJson(),
      };
}
